package cn.itcast.mq.listener;

import lombok.extern.slf4j.Slf4j;
import org.springframework.amqp.rabbit.annotation.*;
import org.springframework.stereotype.Component;

@Component
@Slf4j
public class SpringRabbitListener {

    @RabbitListener(
            bindings = @QueueBinding(
                    value = @Queue(
                            value = "simple.queue"
                    ),
                    exchange = @Exchange(
                            value = "simple.topic.exchange",
                            type = "topic"
                    ),
                    key = "*.*"
            )
    )
    public void listenSimpleQueue(String msg) {
        log.info("消费者接收到simple.queue的消息：{}", msg);
        System.out.println("模拟执行业务");
        int i = 1 / 0;
    }


  /*  *//**
     * 用于接收那些 重试依然失败业务消息，交给人工处理
     * @param msg
     *//*
    @RabbitListener(
            bindings = @QueueBinding(
                    value = @Queue(
                            value = "error.queue"
                    ),
                    exchange = @Exchange(
                            value = "error.direct",
                            type = "direct"
                    ),
                    key = "error"
            )
    )
    public void listenErrorQueue(String msg) {
        log.info("重试依然失败业务消息，将业务消息存入数据库，由人工处理。错误消息：{}",msg);
    }


    *//**
     * 死信监听器
     * @param msg
     *//*
    @RabbitListener(bindings = @QueueBinding(
            value = @Queue(name = "dl.ttl.queue", durable = "true"),
            exchange = @Exchange(name = "dl.ttl.exchange"),
            key = "dl"
    ))
    public void listenDlQueue(String msg){
        log.info("死信消息，将来由人工处理。接收到 dl.ttl.queue的延迟消息：{}", msg);
    }


    @RabbitListener(bindings = @QueueBinding(
            value = @Queue(name = "delay.queue", durable = "true"),
            exchange = @Exchange(name = "delay.exchange",delayed = "true"),
            key = "delay"
    ))
    public void listenDelayQueue(String msg){
        log.info("接收到 dl.ttl.queue的延迟消息：{}", msg);
    }



    *//**
     * 惰性队列
     *//*
    @RabbitListener(bindings = @QueueBinding(
            value = @Queue(name = "lazy.queue",
                    durable = "true",
                    arguments = @Argument(name = "x-queue-mode",value = "lazy")),
            exchange = @Exchange(name = "lazy.exchange"),
            key = "lazy"
    ))
    public void listenLazyQueue(String msg) throws InterruptedException {
        log.info("接收到 lazy.queue的延迟消息：{}", msg);
    }

    *//**
     * 正常队列
     *//*
    @RabbitListener(bindings = @QueueBinding(
            value = @Queue(name = "normal.queue",
                    durable = "true"),
            exchange = @Exchange(name = "normal.exchange"),
            key = "normal"
    ))
    public void listennormalQueue(String msg) throws InterruptedException {
        log.info("接收到 normal.queue的延迟消息：{}", msg);
    }*/
}
